package com.zzyq.pc.utils;

import java.math.BigInteger;
import java.util.Random;
import java.util.UUID;

/**
 * Copyright dayhr2013-2014 All rights reserved
 * 
 * @ClassName: DayHRUUID.java
 * @Description: TODO
 * 
 * @author luojiayong<jiayong_luo@dayhr.com>
 * @version V1.0
 * @Date 2014-7-3 下午2:48:09
 */
public class UUIDUtils {

    private static final Random random = new Random();

    /***
     * 
     * @Title: getUUID
     * @Description: 32位16进制的字符串
     * @param: @return
     * @return: String
     * @throws @author
     *             luojiayong<jiayong_luo@dayhr.com>
     * @Date 2014-7-3 下午2:53:55
     */
    public static String getUUID() {
        UUID uuid = UUID.randomUUID();
        String idstr = uuid.toString().replace("-", "");
        return idstr.toUpperCase();
    }

    /**
     * 
     * @Title: generateGUID
     * @Description: 返回32位字符串 (不限16进制)
     * @param: @return
     * @return: String
     * @throws @author
     *             luojiayong<jiayong_luo@dayhr.com>
     * @Date 2014-7-3 下午2:58:52
     */
    public static String generateGUID() {
        return new BigInteger(165, 32, random).toString(36).toUpperCase();
    }

    /**
     * 生成8位随机字符串 by wangxuejuan
     */
    public static String generateShortUuid() {
        String[] chars = new String[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p",
                "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A",
                "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V",
                "W", "X", "Y", "Z" };
        StringBuffer shortBuffer = new StringBuffer();
        String uuid = UUID.randomUUID().toString().replace("-", "");
        for (int i = 0; i < 8; i++) {
            String str = uuid.substring(i * 4, i * 4 + 4);
            int x = Integer.parseInt(str, 16);
            shortBuffer.append(chars[x % 0x3E]);
        }
        return shortBuffer.toString();

    }

    public static void main(String[] args) {
        System.out.println(getUUID());
    }

}
